<!--
 * @Author: shenya
 * @Date: 2023-11-27 14:42:00
 * @Description: 规则弹框
-->
<template>
  <div>
    <el-dialog
      title="查看规则内容"
      :visible.sync="visible"
      width="50%"
      append-to-body
    >
      <div v-html="content"></div>
    </el-dialog>
  </div>
</template>
<script>
import { selectRulesByCode } from '@/api/core/rules';
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      content: '',
    };
  },
  computed: {
    visible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit('input', val);
      },
    },
  },
  watch: {
    visible(val) {
      if (val) {
        this.getDetail();
      }
    },
  },
  methods: {
    getDetail() {
      selectRulesByCode('GZ0014').then((res) => {
        const content = res.data.data.content || '';
        this.content = this.tableTagAddBorder(content);
        console.log('content666888', res);
      });
    },
    tableTagAddBorder(htmlstr) {
      //正则匹配所有table标签
      var regex1 = new RegExp(
        '(i?)(\<table)(?!(.*?style=[\'"](.*)[\'"])[^>]+>)',
        'gmi'
      );
      //给table标签加上border="1"
      htmlstr = htmlstr.replace(regex1, '$2 border="1"$3');
      console.log('增加style=""后的html字符串6666666666：' + htmlstr);
      return htmlstr;
    },
  },
};
</script>
<style lang="scss" scoped></style>
